<?php
/**
 * UserService.php
 *
 * @copyright  2023 beikeshop.com - All Rights Reserved
 * @link       https://beikeshop.com
 * @author     TL <mengwb@guangda.work>
 * @created    2023-06-09 10:12:57
 * @modified   2023-06-09 10:12:57
 */

namespace Beike\Seller\Services;

use Beike\Seller\Repositories\UserRepo;
use Illuminate\Support\Facades\Hash;

class UserService
{
    /**
     * 修改当前登录用户密码
     *
     * @param array $data ['password', 'new_password']
     * @return bool
     * @throws \Exception
     */
    public static function changePassword(array $data)
    {
        if (! Hash::check($data['password'], current_seller_user()->password)) {
            throw new \Exception(trans('seller::edit.error_old_password'));
        }

        return UserRepo::changePassword(current_seller_user(), $data['new_password']);
    }
}
